package com.itheima.mall.commons;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.itheima.mall.exception.ConsumerException;
import lombok.Data;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;

@Data
public class PageBean<T> implements Serializable {
    private long pageNum;
    private long pageSize;
    private long total;
    private long totalPage;

    private  List<T> list;
//    private HashMap<String, List<T>> data;

    public PageBean() {
    }

    public PageBean(IPage<T> page) {

        List<T> records = page.getRecords();
//        if (ObjectUtil.isEmpty(records)) throw new ConsumerException("暂无数据");
        this.pageSize = page.getSize();

        this.pageNum = page.getCurrent();
        this.total = page.getTotal();
        this.totalPage = page.getPages();


//        HashMap<String, List<T>> list = new HashMap<>();
//        list.put("list", records);
        this.list = records;
    }
}
